<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('需求单列表')" />
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 100px;">需求分类：</label>
                                <input type="text" name="requireTypeName"/>
                            </li>
                            <li>
                                <label style="width: 100px;">用户名：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label style="width: 100px;">需求标题：</label>
                                <input type="text" name="requireTitle"/>
                            </li>
                            <li style="width: 700px;">
                                <label style="width: 100px;">发布区域：</label>
                                <div class="col-sm-8">
                                    <select class="selectpicker form-control" onchange="initCity()" id="requireProvince" name="requireProvince">
                                        <option value="">--省份--</option>
                                    </select>
                                    <select class="selectpicker form-control" onchange="initRegion()" id="requireCity" name="requireCity">
                                        <option value="">--城市--</option>
                                    </select>
                                    <select class="selectpicker form-control" id="requireDist" name="requireDist">
                                        <option value="">--县区--</option>
                                    </select>
                                </div>
                            </li>
                            <!--<li>
                                <label style="width: 100px;">需求描述：</label>
                                <input type="text" name="requireDesc"/>
                            </li>-->
                            <li>
                                <label style="width: 100px;">需求预算：</label>
                                <input type="text" name="requirePrice"/>
                            </li>
                            <li>
                                <label style="width: 120px;">需求联系方式：</label>
                                <input type="text" name="requireTel"/>
                            </li>
                            <li>
                                <label style="width: 120px;">选择联系方式：</label>
                                <select name="requireChoice">
                                    <option value="">所有</option>
                                    <option value="0">电话</option>
                                    <option value="1">报名</option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 100px;">是否匿名：</label>
                                <select name="isNoname">
                                    <option value="">所有</option>
                                    <option value="0">是</option>
                                    <option value="1">否</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
               <!-- <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="lm:require:add">
                    <i class="fa fa-plus"></i> 添加
                </a>-->
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="lm:require:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="lm:require:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
               <!-- <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="lm:require:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
     </div>
     <th:block th:include="include :: footer" />
     <th:block th:include="include :: jquery-cxselect-js" />
     <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
     <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('lm:require:edit')}]];
        var removeFlag = [[${@permission.hasPermi('lm:require:remove')}]];
        var prefix = ctx + "lm/require";

        $(document).ready(function(){
            // 地区下拉框初始化
            $("#requireProvince").selectpicker({width:130, liveSearch: true, liveSearchPlaceholder: "搜索" });
            $("#requireCity").selectpicker({width:120, liveSearch: true, liveSearchPlaceholder: "搜索" });
            $("#requireDist").selectpicker({width:120, liveSearch: true, liveSearchPlaceholder: "搜索" });

            // 动态加载省份选项数据
            initSelectOptions("requireProvince","0");
        });// onReady

        /**
         * 动态生成select选项
         * @param selectId
         * @returns
         */
        function initSelectOptions(selectId,parentId) {
            var selectObj = $("#" + selectId);
            $.ajax({
                url : "require/"+parentId,
                async : false,
                type : "GET",
                success : function(result) {

                        var configs = result.rows;
                        selectObj.find("option:not(:first)").remove();
                        for (var i in configs) {
                            var addressConfig = configs[i];
                            var optionValue = addressConfig.id;
                            var optionText = addressConfig.areaName;
                            selectObj.append(new Option(optionText, optionValue));
                        }
                        debugger;
                        // 刷新select
                        selectObj.selectpicker('refresh');
                },
                error : function(result) {
                    toastr.error('获取['+ parentId + ']信息失败，原因：' + result.errorMessage);
                }
            });// ajax
        }

        /**
         * 根据选择的省份动态初始化城市options
         * @returns
         */
        function initCity() {
            // 当省份变动时，初始化城市和清空县区和街道
            var provinceSel = $("#requireProvince").val();
            initSelectOptions("requireCity", provinceSel);
            $("#requireDist").find("option:not(:first)").remove();
            $("#requireDist").selectpicker('refresh');
           /* $("#street").find("option:not(:first)").remove();
            $("#street").selectpicker('refresh');*/
        }

        /**
         * 根据选择的城市动态初始化区域options
         * @returns
         */
        function initRegion() {
            // 选择城市
            var citySel = $("#requireCity").val();
            initSelectOptions("requireDist", citySel);
        }

      /*  /!**
         * 根据选择的县区动态初始化街道options
         * @returns
         *!/
        function initStreet() {
            // 选择县区
            var regionSel = $("#region").val();
            initSelectOptions("street", regionSel);
        }*/


        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "需求单",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'requireTypeName',
                    title: '需求分类'
                },
                {
                    field: 'requirePic',
                    title: '需求主图',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value,'auto','800px','self');
                    }
                },
                {
                    field: 'userName',
                    title: '用户名'
                },
                {
                    field: 'requireTitle',
                    title: '需求标题'
                }/*,
                {
                    field: 'requireContent',
                    title: '需求发布内容'
                },
                {
                    field: 'requireImages',
                    title: '需求发布图片'
                }*/,
                {
                    field: 'provinceName',
                    title: '需求发布省份'
                },
                {
                    field: 'cityName',
                    title: '需求发布城市'
                },
                {
                    field: 'distName',
                    title: '需求发布区域'
                }/*,
                {
                    field: 'requireDesc',
                    title: '需求描述'
                }*/,
                {
                    field: 'requirePrice',
                    title: '需求预算'
                },
                {
                    field: 'requireTel',
                    title: '需求联系方式'
                },
                {
                    field: 'requireChoice',
                    title: '选择联系方式'
                },
                {
                    field: 'isNoname',
                    title: '是否匿名'
                }
                ,
                {
                    field: 'requireStatus',
                    title: '需求状态'
                }
                ,
                {
                    field: 'signNum',
                    title: '报名人数'
                }
                ,
                {
                    field: 'clickPhoneNum',
                    title: '拨打电话人数'
                }
                ,
                {
                    field: 'requireReason',
                    title: '下架原因'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
/*                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');*/
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewRequire(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        if(row.requireStatus == "上架"){
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="stopRequire(\'' + row.id + '\')"><i class="fa fa-edit"></i>需求下架</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function viewRequire(id) {
            debugger;
            //$.modal.openNoBtn("查看活动",ctx+"lm/activity/view/"+id);
            var title="查看需求";
            var url=ctx+"lm/require/view/"+id;
            var width;
            var height;
            var callback;
            //如果是移动端，就使用自适应大小弹窗
            if ($.common.isMobile()) {
                width = 'auto';
                height = 'auto';
            }
            if ($.common.isEmpty(title)) {
                title = false;
            }
            if ($.common.isEmpty(url)) {
                url = "/404.html";
            }
            if ($.common.isEmpty(width)) {
                width = 800;
            }
            if ($.common.isEmpty(height)) {
                height = ($(window).height() - 50);
            }
            if ($.common.isEmpty(callback)) {
                callback = function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                }
            }
            layer.open({
                type: 2,
                area: [width + 'px', height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: title,
                content: url,
                // 弹层外区域关闭
                shadeClose: true,
                yes: callback,
                cancel: function(index) {
                    return true;
                }
            });
        }
        function stopRequire(id) {
            debugger;
            $.modal.open('需求下架', prefix + "/stop/"+id, '900', '320');
        }
    </script>
</body>
</html>